package com.jinly.ryder.common.error;

/**
 * 错误类型接口
 */
public interface ErrorType {

    /**
     * 错误代码
     */
    String getErrCode();

    /**
     * 错误信息
     */
    String getErrMsg();

    default void throwError() {
        throw buildError();
    }

    default void throwError(String message) {
        throw buildError(message);
    }

    default void throwError(Object errData) {
        throw buildError(errData);
    }

    default void throwError(String message, Object errData) {
        throw buildError(message, errData);
    }

    default ErrorException buildError() {
        ErrorInfo errorInfo = new ErrorInfo(getErrCode(), getErrMsg());
        return new ErrorException(errorInfo);
    }

    default ErrorException buildError(String message) {
        ErrorInfo errorInfo = new ErrorInfo(getErrCode(), message);
        return new ErrorException(errorInfo);
    }

    default ErrorException buildError(String message, Object errData) {
        ErrorInfo errorInfo = new ErrorInfo(getErrCode(), message);
        errorInfo.setErrData(errData);
        return new ErrorException(errorInfo);
    }

    default ErrorException buildError(Object errData) {
        ErrorInfo errorInfo = new ErrorInfo(getErrCode(), getErrMsg());
        errorInfo.setErrData(errData);
        return new ErrorException(errorInfo);
    }

}
